package com.wgxmkalftp.usercenter.service;

import com.wgxmkalftp.user.service.CodeService;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * @author wgx
 * @description
 * @create 2021/3/9/11:29/
 * @origin packageName:com.wgxmkalftp.usercenter.service    projectName:PersonalityWallet
 * @since
 */
@Service(version = "1.0.0")
public class CodeServiceImpl implements CodeService {

    private RedisTemplate<String,String> redisTemplate;

    @Override
    public Boolean verifyCode(String phone,String checkCode) {
        try {
            String redisKey="USER_"+phone;
            if (!redisTemplate.hasKey(redisKey)){
                return false;
            }
            String checkCodeVal = redisTemplate.opsForValue().get(redisKey);
            if (StringUtils.equals(checkCode,checkCodeVal)){
                return true;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return false;
    }
}
